//
//  LXReturnCarViewController.m
//  ZuLinProject
//
//  Created by bancheng on 2021/12/24.
//  Copyright © 2021 LX_App. All rights reserved.
//

#import "LXReturnCarViewController.h"
#import "LXTableViewCell.h"
#import "LXApplyAnnexTableCell.h"
#import "LXChooseBtnTableViewCell.h"
#import "LXRepairModel.h"
#import "LXRemarkTabelViewCell.h"
#import "LXPhotoHelper.h"
#import "LXChooseManagerViewController.h"
#import "FuZeRenModel.h"
#import "LXCarDetailTableViewCell.h"
#import "LXReturnNumTableViewCell.h"
#import "FuZeRenModel.h"
#import "LXReturnCarBottomTableViewCell.h"
#import "LXCarEditViewController.h"
#import "LXCarSignListViewController.h"
#import "LXRepairRecordViewController.h"
#import "LXInsuranceUseRecordViewController.h"
#import "LXPaymentRecordViewController.h"
@interface LXReturnCarViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic) UITableView *tableView;
@property (nonatomic) NSMutableArray *data;
@property (nonatomic) NSMutableDictionary *loanDic;
@property (nonatomic) NSDictionary *selDic;
@property (nonatomic) NSMutableArray *annexAry; //  维修图片  展示用
@property (nonatomic) NSMutableArray *annexDataAry; //  维修图片 提交用

@property (nonatomic) NSString *carManagerId; // 负责人id
@property (nonatomic) FuZeRenModel *fuZeModel; //  负责人模型
@property (nonatomic) NSInteger returnType; //  退车类型 0 正常退车 1 违约退车
/**应退押金金额*/
@property (nonatomic)  NSString *depositPrice;

@end

@implementation LXReturnCarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self layoutCustomNav:self.view title:@"退车"];

    
    NSDictionary *dic = @{
        @"url":@"upLoad_B",
    };
    self.annexAry = [NSMutableArray array];
    self.annexDataAry = [NSMutableArray array];
    [self.annexAry addObject:dic];
    
    [self.tableView registerClass:[LXTableViewCell class] forCellReuseIdentifier:NSStringFromClass([LXTableViewCell class])];
    [self.tableView registerClass:[LXApplyAnnexTableCell class]
         forCellReuseIdentifier:NSStringFromClass([LXApplyAnnexTableCell class])];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([LXRemarkTabelViewCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([LXRemarkTabelViewCell class])];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([LXCarDetailTableViewCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([LXCarDetailTableViewCell class])];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([LXReturnNumTableViewCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([LXReturnNumTableViewCell class])];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([LXReturnCarBottomTableViewCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([LXReturnCarBottomTableViewCell class])];

    

    
    
    
    self.view.backgroundColor = White_Color;
    [self.view addSubview:self.tableView];
    
    [self loadData];
    
    [self setBottomViewWithText:@"确认"];
    
    
    
}
- (void)loadData{
    
    self.loanDic  = [NSMutableDictionary dictionary];
    // 应退押金
    [self.loanDic setValue:self.carModel.depositPrice forKey:@"refundDeposit"];
    self.depositPrice = self.carModel.depositPrice;
    ;
    
    [self.loanDic setValue:[YLUserMgr fetchUser].realName forKey:@"carManagerName"];
    self.carManagerId = USER_ID;
    
    [self.loanDic setValue:[NSString stringWithFormat:@"%@ | %@",self.carModel.carNumber,self.carModel.driverName] forKey:@"carNum"];
    
    self.returnType = 0;
    [self.loanDic setValue:@"正常退车" forKey:@"returnType"];

    NSArray *ary0 = @[
        @{
            @"title":@"退车车辆",
            @"key":@"carNum",
            @"sel":@"clickCarNumAction",
            @"height":@(kComHeight)
        },

    ];
    [self.data addObject:ary0];
    
    
    
    NSArray *ary1 = @[
        @{
            @"title":@"退车明细",
            @"key":@"carDetail",
            @"placeHolder" : @"",
            @"canEdit":@(NO),
            @"showAccess":@(NO),
            @"maxLength":@(1000),
            @"sel":@"",
            @"height":@(145)
        },

    ];
    [self.data addObject:ary1];
    
    NSArray *ary2 = @[
        @{
            @"title":@"里程数(Km)",
            @"key":@"totalMileage",
            @"placeHolder" : @"请输入里程数",
            @"canEdit":@(YES),
            @"inputType":@(NUM_DECIMAL),
            @"keyboardType":@(UIKeyboardTypeDecimalPad),
            @"showAccess":@(NO),
            @"maxLength":@(8),
            @"sel":@"",
            @"height":@(kComHeight)
        },
        @{
            @"title":@"租期里程(Km)",
            @"key":@"periodMileage",
            @"placeHolder" : @"请输入里程数",
            @"canEdit":@(YES),
            @"inputType":@(NUM_DECIMAL),
            @"keyboardType":@(UIKeyboardTypeDecimalPad),
            @"showAccess":@(NO),
            @"maxLength":@(8),
            @"sel":@"",
            @"height":@(kComHeight)
        },
        @{
            @"title":@"*退车状态",
            @"key":@"returnType",
            @"placeHolder" : @"请选择退车状态",
            @"height":@(kComHeight),
            @"showAccess":@(YES),
            @"sel":@"clickCarReturnTypeAction",
        },
        @{
            @"title":@"违约金(元)",
            @"key":@"deductBreach",
            @"placeHolder" : @"请输入违约金",
            @"canEdit":@(YES),
            @"inputType":@(NUM_DECIMAL),
            @"keyboardType":@(UIKeyboardTypeDecimalPad),
            @"showAccess":@(NO),
            @"maxLength":@(6),
            @"sel":@"",
            @"height":@(kComHeight)
        },
        
        @{
            @"title":@"车损金额(元)",
            @"key":@"deductDamage",
            @"placeHolder" : @"请输入车损金额",
            @"canEdit":@(YES),
            @"showAccess":@(NO),
            @"inputType":@(NUM_DECIMAL),
            @"keyboardType":@(UIKeyboardTypeDecimalPad),
            @"maxLength":@(8),
            @"sel":@"",
            @"height":@(kComHeight)
        },
        @{
            @"title":@"待处理违章(元)",
            @"key":@"deductIllegal",
            @"placeHolder" : @"请输入违章金额",
            @"canEdit":@(YES),
            @"showAccess":@(NO),
            @"inputType":@(NUM_DECIMAL),
            @"keyboardType":@(UIKeyboardTypeDecimalPad),
            @"maxLength":@(1000),
            @"sel":@"",
            @"height":@(kComHeight)
        },
        @{
            @"title":@"其他金额(元)",
            @"key":@"deductOther",
            @"placeHolder" : @"请输入其他金额",
            @"canEdit":@(YES),
            @"showAccess":@(NO),
            @"maxLength":@(7),
            @"inputType":@(NUM_DECIMAL),
            @"keyboardType":@(UIKeyboardTypeDecimalPad),
            @"sel":@"",
            @"height":@(kComHeight)
        },
        @{
            @"title":@"*应退押金金额(元)",
            @"key":@"refundDeposit",
            @"placeHolder" : @"请输入应退押金金额",
            @"keyboardType":@(UIKeyboardTypeDecimalPad),
            @"inputType":@(NUM_DECIMAL),
            @"canEdit":@(YES),
            @"showAccess":@(NO),
            @"maxLength":@(10),
            @"sel":@"",
            @"height":@(kComHeight)
        },
        @{
            @"title":@"*应退押金日期",
            @"key":@"refundDepositDate",
            @"placeHolder" : @"请选择应退押金日期",
            @"canEdit":@(NO),
            @"showAccess":@(YES),
            @"maxLength":@(1000),
            @"sel":@"clickReturnDepostAction",
            @"height":@(kComHeight)
        },
        
        @{
            @"title":@"处理车管",
            @"key":@"carManagerName",
            @"placeHolder" : @"请选择处理车管",
            @"height":@(kComHeight),
            @"canEdit":@(NO),
            @"showAccess":@(YES),
            @"sel":@"clickEmployeAction",
        },
        @{
            @"title":@"*退车日期",
            @"key":@"carReturnTime",
            @"placeHolder" : @"请选择退车日期",
            @"height":@(kComHeight),
            @"showAccess":@(YES),
            @"sel":@"clickCarReturnAction",
        },
   
        
        
        
    ];
    [self.data addObject:ary2];
    
    NSArray *ary3 = @[
        @{
            @"title":@"退车附加图片(最多9张)",
            @"key":@"annex",
            @"height":@(kComAnnexHeight)
        },

        @{
            @"title":@"备注",
            @"key":@"remark",
            @"height":@(150)
        },
    
    ];
    [self.data addObject:ary3];
    
    NSArray *ary4 = @[
        @{
            @"key":@"bottomView",
            @"height":@(KHeightScale(230))
        }
    
    ];
    [self.data addObject:ary4];
  
    
    [self.tableView reloadData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.data.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.data[section] count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic = self.data[indexPath.section][indexPath.row];
    
    if ([dic[@"key"] isEqualToString:@"annex"]) {
        return [LXApplyAnnexTableCell getCellHeightWithDataSource:self.annexAry] + 30;
    }
    return [dic[@"height"] doubleValue];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSDictionary *dic = self.data[indexPath.section][indexPath.row];
    if ([dic[@"key"] isEqualToString:@"bottomView"]) {
        
        LXReturnCarBottomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([LXReturnCarBottomTableViewCell class])];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell setClipsToBounds:YES];
        
        [cell setClickAction:^(NSInteger tag) {
            [self pushVC:tag];
        }];
        
        
        
        return cell;
    }
    // 附件
    else if ([dic[@"key"] isEqualToString:@"annex"]) {
        LXApplyAnnexTableCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([LXApplyAnnexTableCell class])];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell setClipsToBounds:YES];
        cell.titleLab.text = dic[@"title"];
        [cell reloadAnnexData:self.annexAry WithMaxNum:9];
        
        
        // 添加图片
        [cell setCallBackTakeAnnex:^(NSInteger num) {
            
            [[LXPhotoHelper shareHelper] showImageViewSelcteWithResultBlock:^(id data) {
                
                [self uploadImage:data];
                
            } andMultipleImageBlock:^(id data) {
                
                [self uploadImage:data];
                
            } andSelectedNum:9 - self.annexDataAry.count];
            
        }];
        
        
        // 放大图片
        [cell setCallBackExtendAnnex:^(NSInteger num,id obj) {
            LXBigImageView *view = [[LXBigImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) WithShowImageAry:self.annexDataAry];
            [view.scrollView setContentOffset:CGPointMake(ScreenWidth*num, 0) animated:NO];
            [[UIApplication sharedApplication].delegate.window addSubview:view];
            
        }];
        // 删除图片
        [cell setCallBackDeleteAnnex:^(NSInteger num) {
            
            [self.annexAry removeObjectAtIndex:num];
            [self.annexDataAry removeObjectAtIndex:num];

            [self.tableView reloadData];
        }];
        
        
        return cell;
    }
    // 退车明细
   else if([dic[@"key"]  isEqualToString:@"carDetail"]){
       LXCarDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([LXCarDetailTableViewCell class])];
       cell.selectionStyle = UITableViewCellSelectionStyleNone;
       [cell setClipsToBounds:YES];
       cell.model = self.carModel;
       return cell;
   }
   
    // 备注
   else if([dic[@"key"]  isEqualToString:@"remark"]){
       LXRemarkTabelViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([LXRemarkTabelViewCell class])];
       cell.selectionStyle = UITableViewCellSelectionStyleNone;
       [cell setClipsToBounds:YES];
       cell.textView.placeholder = @"请输入 ~";
       cell.textView.maxLength = 200;
       cell.remarkTitle.text = dic[@"title"];
       cell.textView.text = self.loanDic[dic[@"key"]];
       [cell setTextViewEdit:^(NSString * _Nonnull textStr) {
           self.loanDic[dic[@"key"]]  = textStr;
       }];
       return cell;
   }
    
    
    if([dic[@"key"]  isEqualToString:@"carNum"]){
        
        LXReturnNumTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([LXReturnNumTableViewCell class])];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell setClipsToBounds:YES];
        cell.carNumLab.text = self.loanDic[dic[@"key"]];
        return cell;

    }
   
    
    LXTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([LXTableViewCell class])];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell setClipsToBounds:YES];
    

    cell.cellDic = dic;
    cell.textFiled.hidden = NO;
    cell.subTitleLab.hidden = YES;
    cell.textFiled.text = self.loanDic[dic[@"key"]];
    
    

    

    cell.textfiledChangeBlock = ^(NSString * _Nonnull textStr) {
        
        
        self.loanDic[dic[@"key"]]  = textStr;
        
        if ([dic[@"key"] isEqualToString:@"deductBreach"] ||
            [dic[@"key"] isEqualToString:@"deductDamage"] ||
            [dic[@"key"] isEqualToString:@"deductIllegal"] ||
            [dic[@"key"] isEqualToString:@"deductOther"]) {
            
            
            textStr = [NSString calculateBySubtractingMinuend:self.depositPrice subtractorNumber:self.loanDic[@"deductBreach"]];
            textStr = [NSString calculateBySubtractingMinuend:textStr subtractorNumber:self.loanDic[@"deductDamage"]];
            textStr = [NSString calculateBySubtractingMinuend:textStr subtractorNumber:self.loanDic[@"deductIllegal"]];
            textStr = [NSString calculateBySubtractingMinuend:textStr subtractorNumber:self.loanDic[@"deductOther"]];
            
            if ([textStr doubleValue] < 0) {
                textStr = @"0";
            }
            
            NSArray *dataArray = self.data[indexPath.section];
            NSPredicate * predicate = [NSPredicate predicateWithFormat:@"key MATCHES[cd] %@", @"refundDeposit"];
            NSDictionary *result = [[dataArray filteredArrayUsingPredicate:predicate] firstObject];
            self.loanDic[result[@"key"]]  = textStr;
            
            
            NSInteger row = [dataArray indexOfObject:result];
            NSIndexPath *indexpath = [NSIndexPath indexPathForRow:row inSection:indexPath.section];
            [self.tableView reloadRowsAtIndexPaths:@[indexpath] withRowAnimation:UITableViewRowAnimationNone];
        }
    
        
    };
    
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSDictionary *dic = self.data[indexPath.section][indexPath.row];
    self.selDic = dic;
    NSString * selName = dic[@"sel"];
    SEL action = NSSelectorFromString(selName);
    if ([self respondsToSelector:action]) {
        [self performSelector:action withObject:nil afterDelay:0];
    }

}



-  (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
    view.backgroundColor = ColorWithF7F8FA;
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}


//MARK: 负责人
-(void)clickEmployeAction{

    [self.view endEditing:YES];
    
    LXChooseManagerViewController *vc = [[LXChooseManagerViewController alloc] init];
    WEAKSELF
    [vc setToSendValue:^(FuZeRenModel * _Nonnull model) {
        [weakSelf.loanDic setValue:model.realName forKey:@"carManagerName"];
        weakSelf.carManagerId = model.ID;
        weakSelf.fuZeModel = model;
        [weakSelf.tableView reloadData];
    }];
    vc.model = self.fuZeModel;
    [self pushToNextController:vc];
    
}
#pragma mark -- 选择应退日期
-(void)clickReturnDepostAction{
    [self.view endEditing:YES];
    DatePickView *datePicker =[[DatePickView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) withDateStr:self.loanDic[@"refundDepositDate"] withIsMaxDate:YES withNoForward:NO WithTips:@"请选择应退押金日期"] ;
    [datePicker showBoomView];
    [[[UIApplication sharedApplication].delegate window] addSubview:datePicker];
    WEAKSELF
    datePicker.block = ^(NSString *yearString){
        [weakSelf.loanDic setObject:yearString forKey:weakSelf.selDic[@"key"]];
        [weakSelf.tableView reloadData];
    };
}
// MARK: 退车类型
-(void)clickCarReturnTypeAction{
    [Tool showSheetTitle:nil msg:nil cancelTitle:@"取消" oneBtnTitle:@"正常退车" twoBtnTitle:@"违约退车" cancelHandlerBlock:^{
    } oneHandlerBlock:^{
        self.returnType = 0;
        [self.loanDic setValue:@"正常退车" forKey:self.selDic[@"key"]];
        [self.tableView reloadData];
    } twoHandlerBlock:^{
        self.returnType = 1;
        [self.loanDic setValue:@"违约退车" forKey:self.selDic[@"key"]];
        [self.tableView reloadData];
    } onVC:self];
}
#pragma mark -- 退车日期
-(void)clickCarReturnAction{
    [self.view endEditing:YES];
    DatePickView *datePicker =[[DatePickView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) withDateStr:self.loanDic[@"carReturnTime"] withIsMaxDate:NO withNoForward:NO WithTips:@"请选择退车日期"] ;
    [datePicker showBoomView];
    [[[UIApplication sharedApplication].delegate window] addSubview:datePicker];
    WEAKSELF
    datePicker.block = ^(NSString *yearString){
        
        if ([NSString compareDate:self.carModel.signStartDate withDate:yearString withFormat:k_DateFormat] == -1) {
            showAlert(@"退车日期不能小于签约日期");
            return;
        }
        
        [weakSelf.loanDic setObject:yearString forKey:weakSelf.selDic[@"key"]];
        [weakSelf.tableView reloadData];
    };
}



- (NSMutableArray *)data{
    if (!_data) {
        _data = [[NSMutableArray alloc]init];
    }
    return _data;
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, kViewTopHeight, ScreenWidth, kScreenHeight - kViewTopHeight - kComHeight - 5) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor colorWithHexString:@"#F7F8FA"];
        _tableView.sectionHeaderHeight = 10;
        _tableView.sectionFooterHeight = 0.00001;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}




#pragma mark ---- 确认新增/修改点击事件
- (void)clickBottomView:(UIButton *)sender{
    
    
    if (StringIsEmpty(self.loanDic[@"refundDeposit"])) {
        showAlert(@"请输入应退押金金额");
        return;
    }
    if ([self.loanDic[@"refundDeposit"] doubleValue] == 0) {
        showAlert(@"应退押金金额不能为0");
        return;
    }
    if (StringIsEmpty(self.loanDic[@"refundDepositDate"])) {
        showAlert(@"请选择应退押金日期");
        return;
    }
    
    if (StringIsEmpty(self.loanDic[@"carReturnTime"])) {
        showAlert(@"请选择退车日期");
        return;
    }
    
    [Tool showAlertTitle:@"该车辆存在逾期的租金,确定要继续退车吗?" msg:nil cancelTitle:@"取消" commitBtnTitle:@"退车" cancelHandlerBlock:^{
        
    } commitHandlerBlock:^{
        [Tool showAlertTitle:@"是否确认提交" msg:nil cancelTitle:@"取消" commitBtnTitle:@"确定" cancelHandlerBlock:^{
        } commitHandlerBlock:^{
            
            
            NSMutableDictionary *dic = @{

                @"carId":self.carModel.carId, // 所属车辆id
                @"carNumber":self.carModel.carNumber,// 所属车辆车牌号
                @"customerId":self.carModel.driverId,// 客户id
                @"customerName":self.carModel.driverName,// 客户id
                @"carManagerName":self.loanDic[@"carManagerName"],// 负责人
                @"returnType":@(self.returnType),//退车类型
                @"carManagerId":self.carManagerId,// 负责人id
                @"totalMileage":self.loanDic[@"totalMileage"],//总里程
                @"periodMileage":self.loanDic[@"periodMileage"],//租期里程
                @"deductBreach":self.loanDic[@"deductBreach"],//违约金
                @"deductDamage":self.loanDic[@"deductDamage"],//车损扣款
                @"deductIllegal":self.loanDic[@"deductIllegal"],//违章扣款
                @"deductOther":self.loanDic[@"deductOther"],//其他扣款
                @"refundDeposit":self.loanDic[@"refundDeposit"],//  应退押金金额
                @"refundDepositDate":self.loanDic[@"refundDepositDate"], //  应退押金日期
                @"carReturnTime":self.loanDic[@"carReturnTime"], //  退车日期
                @"remark":self.loanDic[@"remark"], //  备注
                @"pics":self.annexDataAry, //  维修图片
                
            }.mutableCopy;
            
            NSString *url = POST_PostAddCarReturn;
            
            
            [MSNetworkManager postRevertUrl:url params:dic success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
                
                if (isSuccess) {
                    showAlert(@"退车成功");
                    kUserDefaultSetBool(YES, kRefreshStr);
                    
                    if (!StringIsEmpty(self.fromVc)) {
                        [self backToVC:self.fromVc];
                    }
                    else {
                        [self.navigationController popViewControllerAnimated:YES];
                    }
                    
                  
                }
                
            } failure:^(NSUInteger code, NSString * _Nonnull message) {
            } withShowHud:YES];
        } onVC:self];

    } onVC:self];
 
    
        
 
}

-(void)uploadImage:(NSArray *)ary{
    
    [self.annexAry removeLastObject];
    
    MBProgressHUD *hud = [MBProgressHUD showGif];
        
    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
        
    dispatch_async(queue, ^{
    
    [ary enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
    
        [MSNetworkManager postRevertUrl:POST_UploadFile_URL params:@{@"type":@"1"} formData:@[obj] success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
            if (isSuccess) {
                
                NSString *imageUrl = [NSString stringWithFormat:@"%@%@",HTTP_URL,resonseObj[@"url"]];

                [self.annexAry addObject:@{
                    @"url":imageUrl
                }];
                [self.annexDataAry addObject:resonseObj[@"url"]];
                
                if (idx == ary.count-1) {
                    [hud hide];
                    [self.annexAry addObject:@{
                        @"url":@"upLoad_B",
                    }];
                    [self.tableView reloadData];
                }
                dispatch_semaphore_signal(semaphore);
            }
        } failure:^(NSUInteger code, NSString * _Nonnull message) {
            dispatch_semaphore_signal(semaphore);
            [hud hide];
        } withShowHud:NO];
        
        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
        
        
     }];
    });

}

-(void)pushVC:(NSInteger)tag{
    
    if (tag == 0) {
        
        
        NSString *url = [NSString stringWithFormat:@"%@?id=%@",CarDetail_URL,self.carModel.carId];

        [MSNetworkManager postRevertUrl:url params:@{} success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
            if (isSuccess) {
                CheLiangModel *model = [CheLiangModel mj_objectWithKeyValues:resonseObj[@"carInfo"]];

                LXCarEditViewController *vc = [[LXCarEditViewController alloc] init];
                vc.carModel = model;
                [self pushToNextController:vc];
            }
        } failure:^(NSUInteger code, NSString * _Nonnull message) {
        } withShowHud:YES];
        
        
    }
    else  if (tag == 1) {
        LXCarSignListViewController *vc = [[LXCarSignListViewController alloc] init];
        vc.carNum = self.carModel.carNum;
        [self pushToNextController:vc];
    }
    else  if (tag == 2) {
        LXPaymentRecordViewController *vc = [[LXPaymentRecordViewController alloc] init];
        CheLiangModel *model = self.carModel;
        model.ID = self.carModel.carId;
        vc.carModel = model;
        vc.type = 1;
        [self pushToNextController:vc];
    
    }
    else  if (tag == 3) {
        LXRepairRecordViewController *vc = [[LXRepairRecordViewController alloc] init];
        vc.type = 1;
        vc.carId = self.carModel.carId;
        [self pushToNextController:vc];

    }
    else  if (tag == 4) {
        LXInsuranceUseRecordViewController *vc = [[LXInsuranceUseRecordViewController alloc] init];
        vc.type = 1;
        vc.carId = self.carModel.carId;
        [self.navigationController pushViewController:vc animated:YES];
    
    }
    else  if (tag == 5) {

        
           
    }
    
}

@end
